﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Web.Services;
using System.Web;

public partial class _Search : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    [WebMethod]
    public static List<string> GetAutoCompleteDataName(string prefix)
    {
        List<string> result = new List<string>();
        SqlConnection conn = (SqlConnection)HttpContext.Current.Session["appConn"];
        using (SqlCommand cmd = new SqlCommand())
        {
            cmd.CommandText = "SELECT VtID,VtName,FK_DvtID FROM dmvt WHERE " +
    "VtName like @SearchText + '%'";
            cmd.Parameters.AddWithValue("@SearchText", prefix);
            cmd.Connection = conn;
            //conn.Open();
            using (SqlDataReader sdr = cmd.ExecuteReader())
            {
                while (sdr.Read())
                {
                    result.Add(string.Format("{0}-{1}-{2}", sdr["VtName"], sdr["VtID"],sdr["FK_DvtID"]));
                }
            }
            //conn.Close();
        }
        return result;
    }

    [WebMethod]
    public static List<string> GetAutoCompleteDataValue(string prefix)
    {
        List<string> result = new List<string>();
        SqlConnection conn = (SqlConnection)HttpContext.Current.Session["appConn"];
        using (SqlCommand cmd = new SqlCommand())
        {
            cmd.CommandText = "SELECT VtID,VtName,FK_DvtID FROM dmvt WHERE " +
    "VtID like @SearchText + '%'";
            cmd.Parameters.AddWithValue("@SearchText", prefix);
            cmd.Connection = conn;
            //conn.Open();
            using (SqlDataReader sdr = cmd.ExecuteReader())
            {
                while (sdr.Read())
                {
                    result.Add(string.Format("{0}-{1}-{2}", sdr["VtID"], sdr["VtName"], sdr["FK_DvtID"]));
                }
            }
            //conn.Close();
        }
        return result;
    }

    [WebMethod]
    public static List<string> GetAutoCompleteDVT(string prefix)
    {
        List<string> result = new List<string>();
        SqlConnection conn = (SqlConnection)HttpContext.Current.Session["appConn"];
        using (SqlCommand cmd = new SqlCommand())
        {
            cmd.CommandText = "SELECT DvtID FROM dmdvt WHERE " +
    "DvtID like @SearchText + '%'";
            cmd.Parameters.AddWithValue("@SearchText", prefix);
            cmd.Connection = conn;
            //conn.Open();
            using (SqlDataReader sdr = cmd.ExecuteReader())
            {
                while (sdr.Read())
                {
                    result.Add(sdr["DvtID"].ToString());
                }
            }
            //conn.Close();
        }
        return result;
    }

    [WebMethod]
    public static List<string> GetGiaVon(string ngayCt,string maVT)
    {
        List<string> result = new List<string>();
        SqlConnection conn = (SqlConnection)HttpContext.Current.Session["appConn"];
        using (SqlCommand cmd = new SqlCommand())
        {
            cmd.CommandText = "EXEC fs_Get_gia '@ngayCt','@maVT'";
            cmd.Parameters.AddWithValue("@ngayCt", ngayCt);
            cmd.Parameters.AddWithValue("@maVT", maVT);
            cmd.Connection = conn;
            //conn.Open();
            using (SqlDataReader sdr = cmd.ExecuteReader())
            {
                while (sdr.Read())
                {
                    result.Add(sdr["Gia_von"].ToString());
                }
            }
            //conn.Close();
            //result.Add("11211");
        }
        return result;
    }

}
